﻿/****************************** Module Header ******************************\
 * Module Name:  CMSTextBox.cs
 * Module Version:  1.0.0 (2012-9-13)
 * Copyright (c) AnyEB.Com (14507247@qq.com)
 * 
 * This class is used to process the FormDebugHelper.
 * 
 * This source is subject to the GPL License.
 * See http://www.gnu.org/licenses/gpl.html.
 * All other rights reserved.
 * 
 * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
\***************************************************************************/
using System;
using System.Windows.Forms;

namespace UCF.Core.Forms.CustomControls
{
    /// <summary>
    /// 基本右键菜单
    /// </summary>
    public class CMSTextBox : ContextMenuStrip
    {
        /// <summary>
        /// 复制按钮
        /// </summary>
        private ToolStripMenuItem miCopy = new ToolStripMenuItem("复制");

        /// <summary>
        /// 剪切按钮
        /// </summary>
        private ToolStripMenuItem miCut = new ToolStripMenuItem("剪切");

        /// <summary>
        /// 全选按钮
        /// </summary>
        private ToolStripMenuItem miSelectAll = new ToolStripMenuItem("全选");

        /// <summary>
        /// 清空按钮
        /// </summary>
        private ToolStripMenuItem miClear = new ToolStripMenuItem("清空");

        /// <summary>
        /// 粘帖按钮
        /// </summary>
        private ToolStripMenuItem miPaste = new ToolStripMenuItem("粘帖");

        /// <summary>
        /// 撤销按钮
        /// </summary>
        private ToolStripMenuItem miUndo = new ToolStripMenuItem("撤销");

        public CMSTextBox(params TextBox[] tbs)
        {
            this.miSelectAll.Click += new EventHandler(miSelectAll_Click);
            this.miClear.Click += new EventHandler(miClear_Click);
            this.miCopy.Click += new EventHandler(miCopy_Click);
            this.miCut.Click += new EventHandler(miCut_Click);
            this.miUndo.Click += new EventHandler(miUndo_Click);
            this.miPaste.Click += new EventHandler(miPaste_Click);
            this.Items.Add(miSelectAll);
            this.Items.Add(miCopy);
            this.Items.Add(miCut);
            this.Items.Add(miPaste);
            this.Items.Add(miClear);
            this.Items.Add(miUndo);
            foreach (TextBox tb in tbs)
            {
                tb.ContextMenuStrip = this;
            }
        }
        protected void miSelectAll_Click(object s, EventArgs e)
        {
            ((TextBox)this.SourceControl).SelectAll();
        }
        protected void miCopy_Click(object s, EventArgs e)
        {
            ((TextBox)this.SourceControl).Copy();
        }
        protected void miCut_Click(object s, EventArgs e)
        {
            ((TextBox)this.SourceControl).Cut();
        }
        protected void miPaste_Click(object s, EventArgs e)
        {
            ((TextBox)this.SourceControl).Paste();
        }
        protected void miClear_Click(object s, EventArgs e)
        {
            ((TextBox)this.SourceControl).Clear();
        }
        protected void miUndo_Click(object s, EventArgs e)
        {
            ((TextBox)this.SourceControl).Undo();
        }
    }
}
